package qeb.handheldmedical.adapter;

import org.json.JSONArray;
import org.json.JSONObject;

import qeb.handheldmedical.R;
import qeb.handheldmedical.adapter.InpatientInfoAdapter.ViewHolder;
import android.R.drawable;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author 作者(dugaoyi) E-mail:dugaoyi@163.com
 * @version 创建时间：2016年10月18日 下午2:49:32
 * @declaration
 */
public class InstructionItemAdapter extends BaseAdapter {

	private int mCount;
	private Context mContext;
	private JSONArray JsonData = null;

	public InstructionItemAdapter(Context context, JSONArray data) {

		this.mContext = context;
		this.JsonData = data;
		// mImageLoader = new ImageSwitcher(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		mCount = JsonData.length();
		return mCount;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ViewHolder viewholder = null;
		convertView = LayoutInflater.from(mContext).inflate(
				R.layout.instruction_item, null);
		viewholder = new ViewHolder();
		viewholder.tvgytj = (TextView) convertView.findViewById(R.id.tvgytj);
		viewholder.tvyzmc = (TextView) convertView.findViewById(R.id.tvyzmc);
		viewholder.tvzxsj = (TextView) convertView.findViewById(R.id.tvzxsj);
		viewholder.tvkssj = (TextView) convertView.findViewById(R.id.tvkssj);
		viewholder.tvzssj = (TextView) convertView.findViewById(R.id.tvzssj);
		try {
			JSONObject yz = JsonData.getJSONObject(position);
			if (yz != null) {
				String groupId = "1";
				String provGroupId = "";
				// if (position > 0) {
				// JSONObject provyz = JsonData.getJSONObject(position - 1);//
				// 上一条医嘱数据
				// provGroupId = provyz.getString("GROUPID");
				//
				// }

				String yzmc = yz.getString("YZMC");
				String zxsj = "执行时间:"
						+ (yz.getString("ZXSJ").equals("null") ? "" : yz
								.getString("ZXSJ"));
				String kssj = "备注:"
						+ (yz.getString("FYBZ").equals("null") ? "" : yz
								.getString("FYBZ"));

				String zssj = "剂量:"
						+ (yz.getString("DCJL").equals("null") ? "" : yz
								.getString("DCJL"))
						+ (yz.getString("JLDW").equals("null") ? "" : yz
								.getString("JLDW"));
				// 同一组药
				if (provGroupId.equals(groupId)) {
					viewholder.tvyzmc.setTextColor(Color.GRAY);
					viewholder.tvzxsj.setTextColor(Color.GRAY);
					viewholder.tvkssj.setTextColor(Color.GRAY);
					viewholder.tvzssj.setTextColor(Color.GRAY);
					viewholder.tvgytj.setVisibility(View.GONE);
					yzmc = "　　" + yzmc;
					kssj = "　　 " + kssj;
					zssj = "　　 " + zssj;
					zxsj = "　　 预计" + zxsj;
				}

				viewholder.tvyzmc.setText(yzmc);
				viewholder.tvgytj.setText(yz.getString("GYFS"));
				viewholder.tvzxsj.setText(zxsj);
				viewholder.tvkssj.setText(kssj);
				viewholder.tvzssj.setText(zssj);

			}
		} catch (Exception e) {
			// TODO: handle exception

		}

		return convertView;
	}

	static class ViewHolder {
		TextView tvgytj;
		TextView tvyzmc;
		TextView tvzxsj;
		TextView tvkssj;
		TextView tvzssj;

	}
}
